# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import pymysql


class TuantiPipeline(object):
    def __init__(self):
        self.db = pymysql.Connect(
            host='127.0.0.1',
            user='root',
            password='1111',
            port=3306,
            db='tuanti',
            charset='utf8'
        )
        self.cur = self.db.cursor()

    def process_item(self, item, spider):
        sql = "insert tuanti values(0,'%s','%s','%s')" % (item['zhuangtai'], item['biaoti_zw'], item['biaoti_en'])
        self.cur.execute(sql)
        self.db.commit()
        return item

    def spider_close(self, item, spider):
        self.cur.close()
        self.db.close()
